package cn.juque.lucenecandy.runner;

import cn.juque.lucenecandy.cache.DirectoryCache;
import cn.juque.lucenecandy.cache.IndexInfoCache;
import cn.juque.lucenecandy.cache.IndexReaderCache;
import cn.juque.lucenecandy.cache.IndexWriterCache;
import cn.juque.lucenecandy.core.datasync.DataSyncRender;
import cn.juque.lucenecandy.core.datasync.listener.CommitListenerRender;
import cn.juque.lucenecandy.core.datasync.listener.MsgWriteListenerRender;
import cn.juque.lucenecandy.core.datasync.listener.TccControllerListenerRender;
import cn.juque.lucenecandy.threads.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>LuceneCandyRunner</li>
 * </ul>
 * @date 2023-12-25
 **/
@Slf4j
@Component
public class LuceneCandyRunner implements ApplicationRunner {

    @Resource
    private IndexInfoCache indexInfoCache;

    @Resource
    private DirectoryCache directoryCache;

    @Resource
    private IndexWriterCache indexWriterCache;

    @Resource
    private IndexReaderCache indexReaderCache;

    @Resource
    private IndexWriterThreadPool indexWriterThreadPool;

    @Resource
    private IndexReaderThreadPool indexReaderThreadPool;

    @Resource
    private DataSyncMsgReadThreadPool dataSyncMsgReadThreadPool;

    @Resource
    private DataSyncMsgWriteThreadPool dataSyncMsgWriteThreadPool;

    @Resource
    private ClearHideDocThreadPool clearHideDocThreadPool;

    @Resource
    private HeartbeatThreadPool heartbeatThreadPool;

    @Resource
    private DataSyncRender dataSyncRender;

    @Resource
    private CommitListenerRender commitListenerRender;

    @Resource
    private MsgWriteListenerRender msgWriteListenerRender;

    @Resource
    private TccControllerListenerRender tccControllerListenerRender;

    @Override
    public void run(ApplicationArguments args) {
        this.indexInfoCache.refresh();
        this.directoryCache.refresh();
        this.indexWriterCache.refresh();
        this.indexReaderCache.refresh();
        this.dataSyncRender.init();
        this.commitListenerRender.init();
        this.msgWriteListenerRender.init();
        this.tccControllerListenerRender.init();
        this.indexWriterThreadPool.init();
        this.indexReaderThreadPool.init();
        this.dataSyncMsgReadThreadPool.init();
        this.dataSyncMsgWriteThreadPool.init();
        this.heartbeatThreadPool.init();
        this.clearHideDocThreadPool.init();
    }
}
